from ckeditor.fields import RichTextFormField
from ckeditor_uploader.widgets import CKEditorUploadingWidget
from django import forms
from taggit.forms import TagField
from taggit_autosuggest.widgets import TagAutoSuggest

# from blog import models
from blog import models

class BlogPageModelForm(forms.ModelForm):
    title = forms.CharField(
        label='title',
        min_length=1,
        max_length=50,
        error_messages={
            'min_length': " 输入您的标题",
            'max_length': " 您的标题超字数啦！"
        },
        widget=forms.TextInput(attrs={'class': "form-control p-0 shadow-none min-vh-5",
                                      'placeholder': " 请输入你的文章内容......",
                                      'rows': "1",
                                      })
    )

    intro = forms.CharField(
        label='intro',
        min_length=1,
        max_length=150,
        error_messages={
            'min_length': " 输入您的文章简介",
            'max_length': " 您的简介超字数啦！"
        },
        widget=forms.Textarea(attrs={'class': "form-control p-0 shadow-none min-vh-15",
                                     'placeholder': " 请输入你的文章简介......",
                                     'rows': "1",
                                     })
    )

    tags = TagField(
        label='标签',
        min_length=1,
        max_length=50,
        widget=TagAutoSuggest(tagmodel='tag',
                              attrs={'class': "form-control p-0 shadow-none min-vh-5",
                                     'placeholder': " 请输入你的文章标签......",
                                     'rows': "1",
                                     })
    )

    # content = RichTextFormField(
    #     label='content',
    #     min_length=1,
    #     max_length=10000,
    #     error_messages={
    #         'min_length': " 输入您的文章内容",
    #         'max_length': " 您的简介超字数啦！"
    #     },
        # widget=forms.Textarea(attrs={'class': "form-control p-0 shadow-none min-vh-15",
        #                              'placeholder': " 请输入你的文章简介......",
        #                              'rows': "1",
        #                              }),

        # widget=CKEditorUploadingWidget(),
    # )

    class Meta:
        model = models.BlogPage

        fields = ['title', 'intro', 'tags', 'content', 'is_public']  # 获取字段，按列表顺序展示

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
